package easy

import "unicode"

/*
时间复杂度:O(L) words中所有单词的总长度
空间复杂度:O(C) 英文字母个数

*/

func findWords(words []string) []string {
	var arr [26]int
	s := "qwertyuiop asdfghjkl zxcvbnm"
	count := 0
	for _, ch := range s {
		if ch == ' ' {
			count++
			continue
		}
		arr[ch-'a'] = count
	}
	result := make([]string, 0)
	for _, word := range words {
		ch := unicode.ToLower(rune(word[0])) - 'a'
		num := arr[ch]
		flag := true
		for i := 1; i < len(word); i++ {
			ch = unicode.ToLower(rune(word[i])) - 'a'
			if arr[ch] != num {
				flag = false
				break
			}
		}
		if flag {
			result = append(result, word)
		}
	}
	return result
}